<script setup lang="ts">
import { ref } from "vue";
const msg = ref("Show info");

type Item = {
  id: number;
  name: string;
};

const a: Item[] = [
  { id: 1, name: "Alice" },
  { id: 2, name: "Bob" },
  { id: 5, name: "Eve" },
];

const b: Item[] = [
  { id: 1, name: "Alice" },
  { id: 3, name: "Charlie" },
];

const c: Item[] = [
  { id: 1, name: "Alice" },
  { id: 4, name: "David" },
];

function hasId(array: Item[], id: number): boolean {
  return array.some((item) => item.id === id);
}

//设数组a,b,c据有相同结构，并有主键字段id,找出在a中所有数据，该数据在b和c中都不存在（以id为判断依据
function findUniqueItems(a: Item[], b: Item[], c: Item[]): Item[] {
  return a.filter((item) => !hasId(b, item.id) && !hasId(c, item.id));
}

function findUniqueItems2(a: Item[], b: Item[], c: Item[]): Item[] {
  return a.filter((aitem) => {
    let r = b.some((bitem) => bitem.id === aitem.id);
    r = r && c.some((citem) => citem.id === aitem.id);
    return r;
  });
}

function findUniqueItems3(a: Item[], b: Item[], c: Item[]): Item[] {
  return a.filter((aitem) => !b.some((bitem) => bitem.id === aitem.id) && !c.some((citem) => citem.id === aitem.id));
}

function test() {
  const result: Item[] = findUniqueItems3(a, b, c);

  console.log(result);
  msg.value = JSON.stringify(result, null, 2);
}
</script>

<template>
  <div class="container">
    <h1>{{ msg }}</h1>
    <button type="button" @click="test">click-test</button>
  </div>
</template>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
  min-height: 100%;
}

button {
  margin-top: 20px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.6em 1.2em;
  font-size: 1em;
  font-weight: 500;
  font-family: inherit;
  background-color: #e1e1e1;
  cursor: pointer;
  transition: border-color 0.25s;
}
button:hover {
  border-color: #646cff;
}
button:focus,
button:focus-visible {
  /* outline: 4px auto -webkit-focus-ring-color; */
  outline: 4px auto #646cff;
}
</style>
